package sort;

public class Test_3 {
    public static void main(String[] args) {
        int []arr={2,56,24,785,12,85,23,3456,123,856,12,84,4235,23,735,58636,3124,523,735,124,8956};
        C.secletsort(arr);
        for(int data:arr){
            System.out.print(data+" ");
        }
    }
    }


class C{
    public static void secletsort(int[]arr){
        //选择排序
        for(int i=0;i<arr.length-1;i++){
            int min=arr[i];
            int index=i;
            for(int j=i+1;j<arr.length;j++){//j==i+1易错
                if(arr[j]<min){
                    min=arr[j];
                    index=j;
                }
            }
            if(index!=i){
                arr[index]=arr[i];
                arr[i]=min;
            }
        }
    }
}
